package com.example.gymmanagebackend.mapper;

import com.example.gymmanagebackend.pojo.Equipment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EquipmentMapper {

    @Options(useGeneratedKeys = true, keyProperty = "equipment_id", keyColumn = "equipment_id")
    @Insert("INSERT INTO Equipment (name, brand, price, quantity, purchase_platform, description) VALUES (#{name}, #{brand}, #{price}, #{quantity}, #{purchase_platform}, #{description})")
    int addEquipment(Equipment equipment);

    @Delete("DELETE FROM Equipment WHERE equipment_id = #{id}")
    int deleteEquipmentById(int id);

    @Update("UPDATE Equipment SET name = #{name}, brand = #{brand}, price = #{price}, quantity = #{quantity}, purchase_platform = #{purchase_platform}, description = #{description} WHERE equipment_id = #{equipment_id}")
    int updateEquipment(Equipment equipment);

    @Select("SELECT * FROM Equipment")
    List<Equipment> getAllEquipments();

    @Select("SELECT * FROM Equipment WHERE equipment_id = #{id}")
    Equipment findEquipmentById(int id);

    // 按器械名搜索的方法
    @Select("SELECT * FROM Equipment WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Equipment> findEquipmentByName(@Param("name") String name);

    @Select("SELECT name, quantity FROM Equipment")
    List<Equipment> getEquipmentQuantity();
}